/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.BookMyDriver.BookMyTrip.controller;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 *
 * @author admin
 */
public class SetDataToBookMyTripTable_DatabaseOperation implements Runnable {

    com.BookMyDriver.BookMyTrip.Model.BookMyTrip_Model book;

    public SetDataToBookMyTripTable_DatabaseOperation(com.BookMyDriver.BookMyTrip.Model.BookMyTrip_Model book) {
        this.book=book;
        Thread t = new Thread(this, "");
        t.start();
    }

    public void run() {

        int    customerId = Integer.parseInt(book.getCustomerId());
        String fromDestination = book.getAddress1();
        String toDestination = book.getAddress2();
        int    days =Integer.parseInt(book.getDays()) ;
        String vehicleName = book.getVehicleName();
        String vehiclePic = book.getVehiclePic();
        int    tourPrice = Integer.parseInt(book.getTourPrice());
        String mapData = book.getMapData();
        double totalDistance = Double.parseDouble(book.getTotalDistance());

        String rawField1 = "";
        String rawField2 = "";
        String rawField3 = "";
        String rawField4 = "";

        int rawField5 = 0;
        int rawField6 = 0;
        int rawField7 = 0;
        int rawField8 = 0;

        SessionFactory sessionFactory=BookMyTrip_HibernateUtil.getSessionFactory();
        Session session=sessionFactory.openSession();
        Transaction transaction=session.beginTransaction();

        Bookmytrip bookmytrip=new Bookmytrip(customerId, fromDestination, toDestination, totalDistance, mapData, days, vehicleName, vehiclePic, tourPrice, rawField1, rawField2, rawField3, rawField4, rawField5, rawField6, rawField7, rawField8);

        session.save(bookmytrip);
        transaction.commit();

        session.close();

    }
}
